home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 418 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: solon.com!not-for-mail
  2. From: msb@sq.com
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion.
  5. Date: 17 Feb 1996 11:55:11 -0600
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4g54pv$ajt@solutions.solon.com>
  10. References: <4fstj7$2l6@solutions.solon.com> <4fu835$9de@solutions.solon.com> <4fvgrm$dv9@solutions.solon.com> <4g28hr$qko@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. I wrote:
  14.  
  15. > > Thus even in ANSI C, if this function is called this way:
  16. > >
  17. > >    extern short p, q, r, test(short,short);
  18. > >    r = test(p,q);
  19. > >
  20. > > the values from p and q are still converted from short to int and back
  21. > > to short.  
  22.  
  23. Thad Smith (ThadSmith@acm.org) responded:
  24. > I find nothing in the Standard that states that the arguments undergo
  25. > integral promotions before being assigned to the function parameters.
  26.  
  27. This is in 6.2.1.1/3.2.1.1, the passage which defines the integral
  28. promotions.  It states that the promotions apply
  29.  
  30. #  in an expression wherever an int or unsigned int may be used.
  31.  
  32. Since the call test(1,2) is permissible, this means that p and q must
  33. be promoted to int.  As noted in my previous posting, they are then
  34. converted right back to short within the caller (since a prototype
  35. was used), and the compiler can easily optimize this out.
  36.  
  37. Another example of this sort of thing is an assignment expression like
  38. p=q, where p and q are short.  q is promoted to int, then demoted back
  39. to short; since the value cannot change, the compiler optimizes out the
  40. conversions.  If you write p=(short)q, then the same reason applies
  41. to each of the expressions q and (short)q, and you end up with *two*
  42. round-trip conversions which should be optimized out.
  43. -- 
  44. Mark Brader, msb@sq.com         "Mark is probably right about something,
  45. SoftQuad Inc., Toronto           but I forget what"     -- Rayan Zachariassen
  46.  
  47. My text in this article is in the public domain.
  48.